﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace KnowlegeAssistant
{
    public partial class AdvModeForm : Form
    {
        public AdvModeForm()
        {
            InitializeComponent();
        }

        private void tabPage2_Enter(object sender, EventArgs e)
        {
            RefreshData();
        }

        private void RefreshData()
        {           
            //Subjects,Themes,Tests
            subjectsComboBox.DataSource = SubjectUtil.GetAllSubjects();
            subjectsComboBox.DisplayMember = "Name";
            if (subjectsComboBox.Items.Count != 0)
            {
                subjectsComboBox.SelectedIndex = 0;
            }
        }

        private void subjectsComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            Subject subj = (Subject)subjectsComboBox.SelectedValue;
            themesComboBox.DataSource = ThemeUtil.GetAllThemes(subj.SubjectID);
            themesComboBox.DisplayMember = "Name";

            if (themesComboBox.Items.Count <= 0) 
            {
                themesComboBox.Text = "";
                testComboBox.Text = "";
            }
        }

        private void themesComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            Theme theme = (Theme)themesComboBox.SelectedValue;
            testComboBox.DataSource = TestUtil.GetAllTests(theme.ThemeID);
            testComboBox.DisplayMember = "Name";

            if (testComboBox.Items.Count <= 0) { testComboBox.Text = ""; }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            TestEditorForm tef = new TestEditorForm();
            tef.ShowDialog();
            RefreshData();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            TestEditorForm tef = new TestEditorForm((Theme)this.themesComboBox.SelectedItem);
            tef.ShowDialog();
            RefreshData();
        }

        private void button3_Click(object sender, EventArgs e)
        {
             Test t = (Test)testComboBox.SelectedValue;
             TestUtil.DeleteTest(t.TestID);
             RefreshData();
        }

        private void всеToolStripMenuItem_Click(object sender, EventArgs e)
        {
            StatisticsForm sf = new StatisticsForm(0,0,0, new User());
            sf.ShowDialog();
        }

        private void группаToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }
    }
}
